export default function mapClick(mapobj, that) {
    return new Promise(function() { // appConfig.mapView  appConfig.sceneView
        //二维地图点击事件
        mapobj.appConfig.mapView.on('click', function(event) {
            let mapP = event.mapPoint;
            if (mapobj.appConfig.mapView.scale <= 50000) {
                debugger
                mapobj.showClickLayer.removeAll();
                let oneMapLayer = null;
                if (mapobj.geoOneMapVisible) {
                    oneMapLayer = mapobj.geoOneMap;
                } else if (mapobj.geoOneMap2020Visible) {
                    oneMapLayer = mapobj.geoOneMap2020;
                }
                if (oneMapLayer) {
                    const queryParams = oneMapLayer.createQuery();
                    queryParams.geometry = mapP; //查询的要素，必须要有拓扑关系的查询
                    queryParams.spatialRelationship = "intersects"; // 拓步关系，即上面的event.mapPoint和图层相交的要素将被查询出来，当然也可以有其他拓扑关系包括包含、相离等，默认为相交，所以如果使用相交的拓扑关系，此处也可以不做说明
                    queryParams.returnGeometry = true; //表示返回的数据是否包含几何要素
                    queryParams.outFields = ['*']
                    oneMapLayer.queryFeatures(queryParams).then(function(results) {
                        let result = results.features[0];
                        result.type = 'XiaoBan'
                        result.attributes.name = '小班信息卡'
                        result.symbol = {
                            type: "simple-fill",
                            color: [51, 51, 204, 0.5],
                            style: "solid",
                            outline: {
                                color: "white",
                                width: 1
                            }
                        };
                        mapobj.showClickLayer.add(result);
                        mapobj.appConfig.mapView.goTo(result);
                        window.mapLayerInit(result);
                        return
                    });
                }
            }
            if (mapobj.locationVisible) {
                mapobj.gistools.searchPlace(mapP).then(()  =>  {
                    let g = {
                        geometry: mapP,
                        attributes: {
                            longitude: mapP.longitude,
                            latitude: mapP.latitude,
                            address: mapobj.gistools.getSearch().results[0].results[0].name
                        },
                        type: 'location',
                        symbol: {
                            type: "picture-marker",
                            url: mapobj.locationImg,
                            width: '28px',
                            height: "35px"
                        },
                    }
                    window.mapLayerInit(g);
                    mapobj.showClickLayer.add(g)        
                });
                mapobj.locationVisible = false;
            }
            mapobj.appConfig.mapView.hitTest(event).then(function(response) {
                if (!response.results[0].graphic.layer) {
                    return;
                }
                var id = response.results[0].graphic.layer.id;
                if (id) {
                    var data = response.results[0].graphic.attributes;
                    var geo = response.results[0].graphic.geometry;
                    switch (id) {
                        case "yuntai":
                            //视域分析
                            that.yunViewData.yuntai = 1;
                            that.yuntaiView(mapobj, [geo]);
                            break;
                        case "dept":
                            debugger
                            that.staionlayerview.highlight(response.results[0].graphic);
                            that.showdeftArea(data);
                            break;
                        case "sbjf":
                            that.createH5Video(data.code);
                            break;
                        case "sourceGraphicsLayer": //资源点，有弹框
                        case "cameraGraphicsLayer":
                        case "sourceGraphicsLayer1": //资源点1，有弹框
                            window.mapLayerInit(response.results[0].graphic);
                            break;
                        case "cultureClickLayer": //生态文化，有弹框
                            window.mapLayerInit(response.results[0].graphic);
                            break;
                        case "GEO_VILLAGEPOINT2019": //村点位，有弹框
                            let g = response.results[0].graphic;
                            g.type = 'village'
                            window.mapLayerInit(g);
                            break;
                        case "GEO_PEOPLEDISPOINT": //村点位，有弹框
                            let result = response.results[0].graphic;
                            result.symbol = {
                                type: "simple-marker",
                                style: "square",
                                color: "blue",
                                size: "10px",
                                outline: {
                                    color: [255, 255, 0],
                                    width: 3
                                }
                            };
                            mapobj.showClickLayer.add(result);
                            result.type = 'peopleDis'
                            window.mapLayerInit(result);
                            break;
                            // case "GEO_WETRESEARCH": // 湿地
                            //     let resWetland = response.results[0].graphic;
                            //     resWetland.symbol = {
                            //         type: "simple-marker", 
                            //         style: "square",
                            //         color: "blue",
                            //         size: "10px",
                            //         outline: { 
                            //           color: [ 255, 255, 0 ],
                            //           width: 3 
                            //         }
                            //       };
                            //     mapobj.showClickLayer.add(result);
                            //     resWetland.type = 'wetland';
                            //     window.mapLayerInit(resWetland);
                            // break;
                        default:
                            break;
                    }
                }
            });
        })

        //三维地图点击事件
        mapobj.appConfig.sceneView.on('click', function(event) {
            if (mapobj.locationVisible) {
                let mapP = event.mapPoint;
                mapobj.gistools.searchPlace(mapP).then(()  =>  {
                    let g = {
                        geometry: mapP,
                        attributes: {
                            longitude: mapP.longitude,
                            latitude: mapP.latitude,
                            address: mapobj.gistools.getSearch().results[0].results[0].name
                        },
                        type: 'location',
                        symbol: {
                            type: "picture-marker",
                            url: mapobj.locationImg,
                            width: '28px',
                            height: "35px"
                        },
                    }
                    window.mapLayerInit(g);
                    mapobj.showClickLayer.add(g)        
                });
                mapobj.locationVisible = false;
            }
            mapobj.appConfig.sceneView.hitTest(event).then(function(response) {
                if (!response.results[0].graphic.layer) {
                    return;
                }
                var id = response.results[0].graphic.layer.id;
                if (id) {
                    var data = response.results[0].graphic.attributes;
                    var geo = response.results[0].graphic.geometry;
                    switch (id) {
                        case "yuntai":
                            //视域分析
                            that.yunViewData.yuntai = 1;
                            that.yuntaiView(mapobj, [geo]);
                            break;
                        case "dept":
                            debugger
                            that.staionlayerview.highlight(response.results[0].graphic);
                            that.showdeftArea(data);
                            break;
                        case "sbjf":
                            that.createH5Video(data.code);
                            break;
                        case "sourceGraphicsLayer": //资源点，有弹框
                            window.mapLayerInit(response.results[0].graphic);
                            break;
                        case "sourceGraphicsLayer1": //资源点，有弹框
                            window.mapLayerInit(response.results[0].graphic);
                            break;
                        case "GEO_VILLAGEPOINT2019": //村点位，有弹框
                            let g = response.results[0].graphic;
                            g.type = 'village'
                            window.mapLayerInit(g);
                            break;
                        default:
                            break;
                    }
                }
            });
        })
    });
}